import axios from '@/api/fetch';
//import * as types from './types';
import SERVER from '@/api/server';

//索赔自动审核规则查询-主机厂

//索赔自动审核规则查询-主页面查询
export const getListByPage = params => axios.post(`${SERVER.CLAIMFAC}/rPAutoRule/getListByPage`,  params );
//Excel导出
// export const excelExport = params => axios.get(`${SERVER.CLAIMFAC}/rPReturnWhMp/getListForExport`, params);
// export const excelExport = params => axios.post(`${SERVER.CLAIMFAC}/rPReturnWhMp/getListForExport`,  params );

export const excelExport = params => {
  return axios({
    url:`${SERVER.CLAIMFAC}/rPReturnWhMp/getListForExport`,
    method: 'get',
    params: params,
    responseType: 'blob'
  });
};
//一般车辆配件类型保修期编辑弹窗的保存
export const editSave = params => axios.post(`${SERVER.CLAIMFAC}/rPAutoRule/updateByPtId`,  params );


//导出
// export const getListForExport = (params) => axios.post(`${SERVER.CLAIMFAC}/rPAutoRule/getListForExport`, params, {
//   responseType: 'blob'
// });
export const getListForExport = params =>
  axios({//用axios发送post请求
    data: params,
    method: 'post',
    url: `${SERVER.CLAIMFAC}/rPAutoRule/getListForExport`,//请求地址
    responseType: 'blob',//表明返回服务器返回的数据类型
    headers: {'Content-Type': 'application/json'}
  })
    .then(res => {//处理返回的文件流
      const blob = new Blob([res.data]);//newBlob([res])中不加data就会返回下图中[objeceobjece]内容（少取一层）
      if (res.headers['content-disposition']) {
        const fileName = decodeURI(res.headers['content-disposition'].split(';')[1].split('=')[1]); //这里可以自定义名称，发现设置xlsx文件类型下载后打开会提示下面图-1的无效报错,所以我用了xls格式
        const elink = document.createElement('a');
        elink.download = fileName;
        elink.style.display = 'none';
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href);//释放URL对象
        document.body.removeChild(elink);
      }
    })

//下载中心导出
export const exporturl = params => axios.post(`/api/cmscloud.excel/downloadExcel/exportExcel/${params.CODE}`, params);
